﻿using KAs.Application;
using KAs.Application.Contract.Dto;
using KAs.SqlSugar;
using SqlSugar;
using System.Threading.Tasks;
using Test.Application.Contract.Dto;
using Test.Application.Contract.Svc;
using Test.Domain;

namespace Test.Application;

public class ProOptionConfigAppService :
    CommonCurdAppService<int, ProOptionConfig, ProOptionConfigCreateDto, ProOptionConfigCreateDto, ProOptionConfigDto>,
    IProOptionConfigAppService
{
    // 如果需要使用其他服务可以在这里定义私有可读变量，并在构造函数中注入

    public ProOptionConfigAppService(IRepository<ProOptionConfig,int> repository) : base(repository)
    {
    }

    // 增删改可重写
    public override Task<long> CreateAsync(ProOptionConfigCreateDto createDto)
    {
        //....
        return base.CreateAsync(createDto);
    }

    // 分页请求必须实现
    public override async Task<PageReturnDto<ProOptionConfigDto>> GetPageListAsync(PageReqDto pageReqDto)
    {
        Expressionable<ProOptionConfig> exp = Expressionable.Create<ProOptionConfig>();
        if (pageReqDto.Condition.Count > 0)
        {
            var condition = pageReqDto.Condition;

            //var nameKey = condition.Keys.FirstOrDefault(x => x.Contains("name", StringComparison.OrdinalIgnoreCase));
            //if (nameKey != null)
            //    exp = exp.And(x => x.Name.Contains(condition[nameKey].ToString()));
        }

        return await PageAsync(pageReqDto.PageIndex, pageReqDto.PageSize, exp, pageReqDto.OrderBy);
    }
}
